/*
 *  $Id: Summon.cs 1233 2010-12-18 17:54:48Z thenn.erannor $
 *  This file is a part of Ragima CCG.
 *  (C) 2008-2010 Ragima development group.
 *
 *  Licensed under the terms of the GNU GPL License version 2.
 *
 */

using System;
using System.Collections.Generic;

using AgateLib;
using AgateLib.Geometry;

using Nereal.Serialization;

namespace Ragima {
    /// <summary>
    /// Тип цели: место для призыва существа.
    /// </summary>
    public class SummonTarget : TargetType {
        /// <summary>
        /// Цель: свободные места на поле.
        /// </summary>
        public static readonly SummonTarget Summon = new SummonTarget(new Languages.Phrase("target.summon"));

        private SummonTarget(Languages.Phrase notice) : base(notice) {
        }

        public override int GetCount(AbstractObject caster) {
            return Constants.FieldSize - caster.Owner.GetCreatureCount();
        }
        public override IEnumerable<Region> GetRegions() {
            for (int i = 0; i < Constants.FieldSize; i++) {
                if (Request.Player.GetCreature(i) == null)
                    yield return new SummonRegion(i);
            }
        }

        public override TargetArgs GetArgs(Region region) {
            var sr = region as SummonRegion;
            return sr != null ? new SummonTargetArgs(Request.Player, Request.Caster, sr.Number) : base.GetArgs(region);
        }

        private class SummonRegion : Region {
            public readonly int Number;

            public SummonRegion(int num) : this(Constants.GetRowRect(num, 2), num) {
            }
            public SummonRegion(Rectangle rect, int num) : base(rect) {
                Number = num;
            }

            public override void Draw() {
                Data.CardSelect1.Draw(Rect.Location);
            }

            public override void OnClick() {
                Game.Current.Target.ClickRegion(this);
            }
        }
    }

    [TypeId("summon")]
    public class SummonTargetArgs : TargetArgs<int> {
        [Serialize, XmlName("target")]
        private int _target;

        public SummonTargetArgs() {
        }
        public SummonTargetArgs(Player player, AbstractObject caster, int target) : base(player, caster) {
            _target = target;
        }

        public override int Target {
            get { return _target; }
        }
    }
}
